# -*- encoding: utf-8 -*-
'''
@File    :   1.py
@Time    :   2022/11/29 16:11:07
@Author  :   Cms 
@Version :   1.0
@Contact :   2267000140@qq.com
@WebSite    :   www.baidu.com
'''

# here put the import lib
# 一、定义一个狗类,里面有一个 列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
#        实现狗的买卖交易方法;  打印输出经过2-3次买卖方法后,剩下的各类狗的数量;

class dog(object):
    dogs = [{'color':'red','number':2,'price':10},
            {'color':'blue','number':2,'price':20},
            {'color':'yellow','number':2,'price':30}]

    # 卖狗
    def sold(self,color):
        for i in self.dogs:
            if i['color'] == color:
                print("卖出了",color,"狗")
                i['number'] -= 1
                print(color,"狗还剩",i['number'],"只")

    # 买狗
    def buy(self,color):
        for i in self.dogs:
            if i['color'] == color:
                print("买了",color,"狗")
                i['number'] += 1
                print(color,"狗还剩",i['number'],"只")
    

    # 输出当前有多少只狗
    def dognum(self):
        for i in self.dogs:
            print(i['color'],':',i['number'],"只")

d = dog()
d.sold('red')
d.buy("red")
d.sold('yellow')
d.dognum()